1) Clean up a number of memory overwrites exposed by running Garmin
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 25 Nov 2002 01:01:39 +0000 (01:01 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 25 Nov 2002 01:01:39 +0000 (01:01 +0000)
protocol under Windows that don't show up with efence on Linux.

2) Don't cross the ident and shortnames of the waypoints.

gpsapp.c) Correct loops for D108 and D109 that are looking at zero
   terminated strings when its own doc says that the input is NOT
   zero terminated strings.  (Why am I rapidly losing faith in jeeps?)

gpsmem.c) Initialize several more waypoint fields on startup.

gpsbabel/garmin.c
gpsbabel/jeeps/gpsapp.c
gpsbabel/jeeps/gpsmem.c

index ce3049e23ecbd274a6b17e3bbe6cbc478cff9f6f..a05dbe2217d5e4ecdd185395b5213046aac34986 100644 (file)
@@ -145,7 +145,7 @@ data_write(void)
        extern int32 gps_save_id;
        int short_length;
 
-       way = xmalloc(n*sizeof(*way));
+       way = xcalloc(n,sizeof(*way));
 
        for (i = 0; i < n; i++) {
                if(!((way)[i]=GPS_Way_New()))
@@ -203,7 +203,8 @@ data_write(void)
        QUEUE_FOR_EACH(&waypt_head, elem, tmp) {
                waypoint *wpt;
                char *ident;
-               char *src;
+               char *src = NULL;
+               char *wptname;
 
                wpt = (waypoint *) elem;
 
@@ -213,20 +214,18 @@ data_write(void)
                ident = global_opts.synthesize_shortnames ? 
                                mkshort(src) : 
                                wpt->shortname;
-
                strncpy(way[i]->ident,  ident, sizeof(way[i]->ident));
-               if (wpt->description) {
-                       strncpy(way[i]->cmnt, wpt->description, 
-                                       sizeof(way[i]->cmnt));
-               } else {
-                       way[i]->cmnt[0] = 0;
+               way[i]->ident[sizeof(way[i]->ident)-1] = 0;
+               if (src && strlen(src)) {
+                       strncpy(way[i]->cmnt, src, sizeof(way[i]->cmnt));
                }
                way[i]->lon = wpt->position.longitude.degrees;
                way[i]->lat = wpt->position.latitude.degrees;
-               way[i]->alt = wpt->position.altitude.altitude_meters;
+               if (wpt->position.altitude.altitude_meters != unknown_alt) {
+                       way[i]->alt = wpt->position.altitude.altitude_meters;
+               }
                i++;
        }
-
        if ((ret = GPS_Command_Send_Waypoint(portname, way, n)) < 0) {
                fatal(MYNAME ":communication error sending wayoints..\n");
        }
index 4937ea1e0338fce9b56c2e5ff58d55527dc91651..898e0f50ae6e81d41dcb2b57b13ddfa222599e98 100644 (file)
@@ -1839,17 +1839,23 @@ static void GPS_D108_Send(UC *data, GPS_PWay way, int32 *len)
 
 
     q = (UC *) way->ident;
-    while((*p++ = *q++));
+    i = sizeof(way->ident);
+    while((*p++ = *q++) && i--);
     q = (UC *) way->cmnt;
-    while((*p++ = *q++));
+    i = sizeof(way->cmnt);
+    while((*p++ = *q++) && i--);
     q = (UC *) way->facility;
-    while((*p++ = *q++));
+    i = sizeof(way->facility);
+    while((*p++ = *q++) && i--);
     q = (UC *) way->city;
-    while((*p++ = *q++));
+    i = sizeof(way->city);
+    while((*p++ = *q++) && i--);
     q = (UC *) way->addr;
-    while((*p++ = *q++));
+    i = sizeof(way->addr);
+    while((*p++ = *q++) && i--);
     q = (UC *) way->cross_road;
-    while((*p++ = *q++));
+    i = sizeof(way->cross_road);
+    while((*p++ = *q++) && i--);
     
     *len = p-data;
     
@@ -1875,7 +1881,6 @@ static void GPS_D109_Send(UC *data, GPS_PWay way, int32 *len)
     int32 i;
     
     p = data;
-
     *p++ = 1 /* way->wpt_class */;     /* For D109, the class must be 1 */
     *p++ = 0 /* way->colour*/ ;                /* If non-zero, the waypoint is in 
                                           invisible ink on the V. */
@@ -1901,20 +1906,24 @@ static void GPS_D109_Send(UC *data, GPS_PWay way, int32 *len)
     for(i=0;i<4;++i) *p++ = 0xff; /* D109 silliness for ETE */
 
     q = (UC *) way->ident;
-    while((*p++ = *q++));
+    i = sizeof(way->ident);
+    while((*p++ = *q++) && i--);
     q = (UC *) way->cmnt;
-    while((*p++ = *q++));
+    i = sizeof(way->ident);
+    while((*p++ = *q++) && i--);
     q = (UC *) way->facility;
-    while((*p++ = *q++));
+    i = sizeof(way->facility);
+    while((*p++ = *q++) && i--);
     q = (UC *) way->city;
-    while((*p++ = *q++));
+    i = sizeof(way->city);
+    while((*p++ = *q++) && i--);
     q = (UC *) way->addr;
-    while((*p++ = *q++));
+    i = sizeof(way->addr);
+    while((*p++ = *q++) && i--);
     q = (UC *) way->cross_road;
-    while((*p++ = *q++));
-    
+    i = sizeof(way->cross_road);
+    while((*p++ = *q++) && i--);
     *len = p-data;
-    
     return;
 }
 
index e2c83679c454748eec564cbd09c7a079a15cd32f..35a95894e086d5e7e80df491d0d1819bbc5249fb 100644 (file)
@@ -232,18 +232,26 @@ GPS_PWay GPS_Way_New(void)
        fflush(stderr);
        return NULL;
     }
-
-    /* Mark all as "unused" */
+    /* 
+     * Mark all as "unused".  These appear in the same order as in struct.
+     * It's wretched that A) memset isn't used.  B) sizeof isn't used. C)
+     * The whole stupid structure isn't simply memsetted sanely. 
+     */
     for(i=0;i<6;++i) ret->ident[i]=' ';
-    for(i=0;i<2;++i) ret->cc[i]=' ';
-    for(i=0;i<18;++i) ret->subclass[i]=' ';
     for(i=0;i<40;++i) ret->cmnt[i]=' ';
+    for(i=0;i<256;++i) ret->wpt_ident[i]=' ';
+    for(i=0;i<256;++i) ret->lnk_ident[i]=' ';
+    for(i=0;i<18;++i) ret->subclass[i]=' ';
+    for(i=0;i<2;++i) ret->cc[i]=' ';
     for(i=0;i<24;++i) ret->city[i]=' ';
     for(i=0;i<2;++i) ret->state[i]=' ';
     for(i=0;i<30;++i) ret->name[i]=' ';
+    for(i=0;i<32;++i) ret->facility[i]=' ';
+    for(i=0;i<52;++i) ret->addr[i]=' ';
+    for(i=0;i<52;++i) ret->cross_road[i]=' ';
+    for(i=0;i<20;++i) ret->rte_cmnt[i]=' ';
+    for(i=0;i<256;++i) ret->rte_ident[i]=' ';
     for(i=0;i<18;++i) ret->rte_link_subclass[i]=' ';
-    for(i=0;i<256;++i) ret->wpt_ident[i]=' ';
-    for(i=0;i<256;++i) ret->lnk_ident[i]=' ';
     for(i=0;i<256;++i) ret->rte_link_ident[i]=' ';
     
     ret->dst = ret->lat = ret->lon = GPS_FLTMAX;